<?php

class LogController extends AdminhtmlController
{
	public $layout='application.modules.adminhtml.views.layouts.column2';
		
	/* this function must write final controller file!! */
	protected function getActionsKey()
	{
		return __CLASS__;
	}
	
	public function init()
	{
		parent::init();
		$this->menu=array(
			1=> array('label'=>'管理记录 [ Grid ]', 'url'=>array('admin')),
			2=> array('label'=>'数据列表 [ List ]', 'url'=>array('index')),
		);
		$this->controllerLable = '管理员日志';
	}
	
	/**
	 * Displays a particular model.
	 * @param integer $id the ID of the model to be displayed
	 */
	public function actionView($id)
	{
		$this->setUnionTitle('查看#'. $id);
		$this->render('view',array( 'model'=>$this->loadModel($id)->with('admin'), ));
	}

	/**
	 * Deletes a particular model.
	 * If deletion is successful, the browser will be redirected to the 'index' page.
	 * @param integer $id the ID of the model to be deleted
	 */
	public function actionDelete($id)
	{
		if(Yii::app()->request->isPostRequest)
		{
			// we only allow deletion via POST request
			$this->loadModel($id)->delete();

			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
			if(!isset($_GET['ajax']))
				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
		}
		else
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
	}

	/**
	 * Lists all models.
	 */
	public function actionIndex()
	{
		$this->setUnionTitle('详细列表');
		$dataProvider=new CActiveDataProvider('AdminhtmlLog');
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
		));
	}

	/**
	 * Manages all models.
	 */
	public function actionAdmin()
	{
		$this->setUnionTitle('管理列表');
		$model=new AdminhtmlLog('search');
		$model->unsetAttributes();  // clear any default values
		if(isset($_GET['AdminhtmlLog']))
			$model->attributes=$_GET['AdminhtmlLog'];

		$this->render('admin',array( 'model'=>$model->with('admin'), ));
	}

	/**
	 * Returns the data model based on the primary key given in the GET variable.
	 * If the data model is not found, an HTTP exception will be raised.
	 * @param integer the ID of the model to be loaded
	 */
	public function loadModel($id)
	{
		$model=AdminhtmlLog::model()->findByPk((int)$id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}

	/**
	 * Performs the AJAX validation.
	 * @param CModel the model to be validated
	 */
	protected function performAjaxValidation($model)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='adminhtml-log-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}
}
